/*
 * @Author: Zeratul
 * @Date: 2020-08-24 02:30:44
 * @LastEditTime: 2020-08-24 14:48:16
 * @FilePath: \sz-h5-2003-react-mobile\zhangminhui\eleme-react\eleme-user\src\store\actionCreator\loginAction\index.js
 */
import { CHANGEINPUTTEL, CHANGEINPUTPASSWORD,LOGIN_200,CODE_200,LOGOUT_200} from "../../actionType";
import axios from "../../../utils/myaxios";
const changeInputTelAction = (params) => ({
  type: CHANGEINPUTTEL,
  params,
});
const changeInputPasswordAction = (params) => ({
  type: CHANGEINPUTPASSWORD,
  params,
});
const handleLoginAction = (...value) => {
  // console.log(value);
if(parseInt(value[1])===value[2]){
  return function (dispatch) {
    axios.post('user/loginByCode',{telephone:value[0]}).then(res=>{
      // console.log(res);
      if(res.code===200){
        dispatch({
          type:LOGIN_200,
          userInfo:res.sqlQueryResults
        })
      }
    })
  };
}else{
  return function (dispatch){
    dispatch({
      type:"",
      userInfo:{}
    })
  }
  
}
};
const getCodeAction =(val)=>{
  // console.log(val);
  return function(dispatch){
    axios.post('/user/getSMSCode',{telephone:val,way:"login"}).then(res=>{
      // console.log(res)
        dispatch({
          type:CODE_200,
          code:res.code
        })
      
    })
  }
}
const logoutAction = ()=>{
  return function (dispatch){
    dispatch({
      type:LOGOUT_200,
      userInfo:{}
    })
  }
}
export {changeInputTelAction, changeInputPasswordAction, handleLoginAction ,getCodeAction,logoutAction}
